package com.hakim.wfb.platform.controller;

import com.hakim.wfb.customer.params.goods.PurchaseListParameter;
import com.hakim.wfb.customer.params.order.AddOrderParameter;
import com.hakim.wfb.customer.result.purchase.PurchaseListView;
import com.hakim.wfb.customer.service.PurchaseService;
import com.hkfs.fundamental.api.data.ListResultEx;
import com.hkfs.fundamental.api.data.ObjectResultEx;
import com.hkfs.fundamental.api.data.ResultEx;
import com.hkfs.fundamental.api.params.SessionIdentity;
import com.hkfs.fundamental.session.SessionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lenovo on 2017/7/3.
 */
@RestController
@RequestMapping("/purchase")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

    @RequestMapping(value = "/addOrder", method = RequestMethod.POST)
    public ResultEx addOrder(AddOrderParameter parameter, HttpServletRequest request) {

        SessionHandler sessionHandler = new SessionHandler();
        SessionIdentity sessionIdentity = sessionHandler.getSessionIdentity(request, SessionIdentity.class);

        parameter.setUserId(sessionIdentity.getUuid());
        parameter.setPhone(sessionIdentity.getPhone());
        return purchaseService.addOrder(parameter);
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ListResultEx<PurchaseListView> getChartList(PurchaseListParameter param, HttpServletRequest request) {

        SessionHandler sessionHandler = new SessionHandler();
        SessionIdentity sessionIdentity = sessionHandler.getSessionIdentity(request, SessionIdentity.class);
        String userid = sessionIdentity.getUuid();
        param.setUserId(userid);
        param.setSessionIdentity(sessionIdentity);
        param.setRequestOffset((param.getPageNo() - 1) * param.getPageSize());
        ListResultEx<PurchaseListView> res = purchaseService.getChartList(param);
        return res;
    }

    @RequestMapping(value = "/delOrder", method = RequestMethod.POST)
    public void deleOrder(String purchaseid, HttpServletRequest request) {
        SessionHandler sessionHandler = new SessionHandler();
        SessionIdentity sessionIdentity = sessionHandler.getSessionIdentity(request, SessionIdentity.class);
        String userid = sessionIdentity.getUserId() + "";
//        purchaseService.delOrder(purchaseid, userid);

    }


}
